﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public enum Group
{
    Player,
    Enemy,
}
/// <summary>
/// 子弹基类
/// </summary>
public class Bullet : MonoBehaviour {

    public Group group;
    protected float speed;

    public virtual void Fire(float speed)
    {
        this.speed = speed;

        this.GetComponent<Rigidbody2D>().velocity = transform.up * speed;
        GameObject.Destroy(gameObject, group == Group.Player ? 2f : 5f);
    }

    void OnTriggerEnter2D(Collider2D collision)
    {
        if (group == Group.Player && collision.tag == "Enemy")
        {
            collision.GetComponent<EnemyHP>().OnHit();
            Destroy(gameObject);
        }
        else if (group == Group.Enemy && collision.tag == "Player")
        {
            //
            Destroy(gameObject);
        }
    }
}
